package com.lbd.mq;

import com.lbd.dynamicCode.bean.MsgSendRecord;
import com.lbd.dynamicCode.service.DynamicCodeService;
import com.lbd.dynamicCode.service.RestService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Demo class
 *
 * @author zzl
 * @date ${date}
 */
@Component
@RabbitListener(queues = "dynamic_code")
public class MessageReceiver {
    @Resource
    private DynamicCodeService dynamicCodeService;
    @Resource
    private RestService restService;
    @RabbitHandler
    public void process(MsgSendRecord record) {
        System.out.println("Rabbit接收到的消息信息："+record.toString());
        MsgSendRecord bean=dynamicCodeService.saveInfo(record);
        try {
            if(restService.getShortUrl(bean).get()==0){
                System.out.println("[获取短链接保存失败->record：为"+bean.id+"]");
            }
        } catch (Exception e) {
            System.out.println("[获取短链接保存失败->record：为"+bean.id+"]");
        }
        System.out.println("Rabbit保存短信信息成功!!!");
    }
}
